<?php
class setsubmenu extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('msetsubmenu');
		$this->load->model('msetmenu');
	}
	
	function index()
	{
		$data['active'] = "submenu";
		$config['base_url'] = base_url().'setsubmenu/index/';
		$config['total_rows'] = $this->db->count_all('set_submenu');
		$config['per_page'] = 10;
		$config['uri_segment'] = 3;
		
		$config['full_tag_open'] = '<div><ul class="pagination pagination-sm">';
		$config['full_tag_close'] = '</ul></div><!--pagination-->';

		$config['first_link'] = '&laquo; First';
		$config['first_tag_open'] = '<li class="prev page">';
		$config['first_tag_close'] = '</li>';

		$config['last_link'] = 'Last &raquo;';
		$config['last_tag_open'] = '<li class="next page">';
		$config['last_tag_close'] = '</li>';

		$config['next_link'] = 'Next &rarr;';
		$config['next_tag_open'] = '<li class="next page">';
		$config['next_tag_close'] = '</li>';

		$config['prev_link'] = '&larr; Previous';
		$config['prev_tag_open'] = '<li class="prev page">';
		$config['prev_tag_close'] = '</li>';

		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';

		$config['num_tag_open'] = '<li class="page">';
		$config['num_tag_close'] = '</li>';
		
		$this->pagination->initialize($config);
		
		$token = $this->session->userdata('token');
		if($token){
			$data['results'] = $this->msetsubmenu->getList($config['per_page'],$this->uri->segment(3));
			$this->load->view('submenu/list',$data);
		}else{
			redirect('login');
		}
	}
    
	function add(){
		$data['active'] = "submenu";
		$data['mode'] = "Tambah";
		$data['action'] = "save";
		$data['menu'] = $this->msetmenu->getComboList();
		$this->load->view('submenu/form',$data);
	}
	
	function edit($id_submenu){
		$data['active'] = "submenu";
		$data['mode'] = "Ubah";
		$data['action'] = "update";
		$data['menu'] = $this->msetmenu->getComboList();
		$data['detail'] = $this->msetsubmenu->detail($id_submenu);
		$this->load->view('submenu/form',$data);
	}
	
	function save()
	{
		$id_submenu = $this->input->post('id_submenu');
		$id_menu = $this->input->post('id_menu');
		$nama_submenu = $this->input->post('nama_submenu');
		$urutan_submenu = $this->input->post('urutan_submenu');
		$type_submenu = $this->input->post('type_submenu');
		$enable_submenu = $this->input->post('enable_submenu');
		
		$submit = $this->input->post('submit');	
		if($submit)
		{
			$this->msetsubmenu->setData($id_submenu,$id_menu,$nama_submenu,$urutan_submenu,$type_submenu,$enable_submenu);
			$this->msetsubmenu->create();
			$this->session->set_flashdata('success', true);
			redirect('setsubmenu');
		}
		$this->session->set_flashdata('error', true);
		redirect('setsubmenu');
	}
	
	function update()
	{
		$id_submenu = $this->input->post('id_submenu');
		$id_menu = $this->input->post('id_menu');
		$nama_submenu = $this->input->post('nama_submenu');
		$urutan_submenu = $this->input->post('urutan_submenu');
		$type_submenu = $this->input->post('type_submenu');
		$enable_submenu = $this->input->post('enable_submenu');
		
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->msetsubmenu->setData($id_submenu,$id_menu,$nama_submenu,$urutan_submenu,$type_submenu,$enable_submenu);
			$this->msetsubmenu->update($id_submenu);
			$this->session->set_flashdata('success', true);
			redirect('setsubmenu');
		}
		$this->session->set_flashdata('error', true);
		redirect('setsubmenu');
	}
	
	function delete($id_submenu)
	{
		if ($this->msetsubmenu->remove($id_submenu)){
			$this->session->set_flashdata('delete', true);
			redirect('setsubmenu','refresh');
		}
		$this->session->set_flashdata('error', true);
		redirect('setsubmenu');
	}	
	
	function searchData(){
		$data['active'] = "submenu";
		$name = $this->input->post('name');
		$data['results'] = $this->msetsubmenu->getListSearch($name);
		$this->load->view('setsubmenu/list',$data);
	}
}
?>